package cn.migu.music.hangupsms.service;

import cn.migu.music.common.exception.BusinessException;
import cn.migu.music.hangupsms.model.CLSmsSendReq;
import cn.migu.music.hangupsms.model.CLSmsSendRsp;
import cn.migu.music.hangupsms.remote.CLSmsFeignClient;
import cn.migu.music.hangupsms.service.inner.InnerProcessBlackUserService;
import cn.migu.music.hangupsms.service.sftp.BlackUserExportSftpService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class AdminController {
    @Autowired
    private BaseService                  baseService;

    @Autowired
    private BlackUserExportSftpService   blackUserExportSftpService;

    @Autowired
    private InnerProcessBlackUserService innerProcessBlackUserService;

    @Autowired
    private CLSmsFeignClient             clSmsFeignClient;

    /**
     * 测试：查询是否开通基础会员
     * 
     * @param msisdn
     *            手机号
     * @return 基础会员状态
     */
    @GetMapping("/cljz-hangupsms/admin/query-base-vip-status/v1.0")
    public String queryBaseVipStatus(@RequestParam("msisdn") String msisdn) {
        return baseService.getBaseVipStatus(msisdn);
    }

    /**
     * 黑名单导出并上传sftp
     * 
     * @param localId
     *            localId
     * @param type
     *            类型： 1：增量，0：全量
     * @param startTime
     *            开始时间
     * @param endTime
     *            结束时间
     * @return
     */
    @GetMapping("/cljz-hangupsms/admin/upload-black-user-sftp/v1.0")
    public String uploadBlackUserSftp(@RequestParam("localId") String localId,
                                      @RequestParam("type") String type,
                                      @RequestParam(value = "startTime", required = false) String startTime,
                                      @RequestParam(value = "endTime", required = false) String endTime) {
        if ((StringUtils.isEmpty(startTime) && StringUtils.isNotEmpty(endTime)) ||
            (StringUtils.isNotEmpty(startTime) && StringUtils.isEmpty(endTime))) {
            throw BusinessException.newInstance("参数错误");
        }

        blackUserExportSftpService.exportBlackUser(localId, type, startTime, endTime);
        return "success";
    }

    /**
     * 回填黑名单表localId
     * 
     * @return
     */
    @GetMapping("/cljz-hangupsms/admin/update-black-user-local-id/v1.0")
    public String updateLocalIdForBlackUser() {
        innerProcessBlackUserService.writeLocalId();
        return "success";
    }

    /**
     * 创蓝文本短信接口
     *
     * @param clSmsSendReq
     *            文本短信请求参数
     * @return 响应参数
     */
    @PostMapping(value = "/cljz-hangupsms/admin/cl-send-sms/v1.0")
    public CLSmsSendRsp sendSms(@RequestBody CLSmsSendReq clSmsSendReq) {
        return clSmsFeignClient.sendSms(clSmsSendReq);
    }

    /**
     * 创蓝视频短信接口
     *
     * @param clSmsSendReq
     *            视频短信请求参数
     * @return 响应参数
     */
    @PostMapping(value = "/cljz-hangupsms/admin/cl-send-vms/v1.0")
    public CLSmsSendRsp sendVms(@RequestBody CLSmsSendReq clSmsSendReq) {
        return clSmsFeignClient.sendVms(clSmsSendReq);
    }
}
